

import { Controller } from 'egg';

export default class ArtistController extends Controller {




    private artistTypes = [
        { name: '入驻歌手', cat: 5001 },
        { name: '华语男歌手', cat: 1001 },
        { name: '华语女歌手', cat: 1002 },
        { name: '华语组合/乐队', cat: 1003 },
        { name: '欧美男歌手', cat: 2001 },
        { name: '欧美女歌手', cat: 2002 },
        { name: '欧美组合/乐队', cat: 2003 },
        { name: '日本男歌手', cat: 6001 },
        { name: '日本女歌手', cat: 6002 },
        { name: '日本组合/乐队', cat: 6003 },
        { name: '韩国男歌手', cat: 7001 },
        { name: '韩国女歌手', cat: 7002 },
        { name: '韩国组合/乐队', cat: 7003 },
        { name: '其他男歌手', cat: 4001 },
        { name: '其他女歌手', cat: 4002 },
        { name: '其他组合/乐队', cat: 4003 },
    ]
    public async index(){
        const url = `/weapi/v1/artist/${this.ctx.query.id}`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', {})
        const { body } = result;
        this.ctx.body = body;

    }

    public async types() {
        this.ctx.body = this.artistTypes;
        
    }


    public async list() {
        const { cat, offset, total, limit, initial } = this.ctx.query;

        const data = {
            categoryCode: this.artistTypes.find(item=>item.cat ===cat) && cat  || "1001",
            offset: offset || 0,
            total: total ? "true" : "false",
            limit: limit || 30,
            initial: (initial || "").toUpperCase().charCodeAt() || ""
        }

        const url = `/weapi/artist/list`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body, cookie } = result;

        cookie && this.service.mequest.parseCookie(cookie).forEach(ck => {
            this.ctx.cookies.set(ck.cookie.name, ck.cookie.value, ck.options)
        })

        this.ctx.body = body;

    }

    public async sublist(){
        const {offset,total,limit}=this.ctx.query;
        const data = {
            offset: offset || 0,
            total: total ? "true" : "false",
            limit: limit || 25
        }
        const url = `/weapi/artist/sublist`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body } = result;
        this.ctx.body = body;
    }

    // /artist/mv?id=7763   
    public async mv(){
        const {id,offset,limit}=this.ctx.query;
        const data = {
            artistId:id,
            offset:offset ||0,
            limit:limit||30,
            total:true
        };
        const url = `/weapi/artist/mvs`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body } = result;
        this.ctx.body = body;
    }
    // /album获取歌手专辑
    public async album(){
        const {id,offset,limit}=this.ctx.query;
        const data = {offset:offset || 0,limit : limit|| 30};
        const url = `/weapi/artist/albums/${id}`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        const { body } = result;
        this.ctx.body = body;
    }
    // 获取歌手描述
    public async desc(){
        const data = {id:this.ctx.query.id};
        const url = `/weapi/artist/introduction`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }

    // 热门歌手
    public async hot(){
        const {offset,limit}=this.ctx.query;
        const data = {
            offset: offset || 0,
            total: true,
            limit: limit || 50,
        }
        const url = `/weapi/artist/top`;
        let result = await this.service.mequest.createWebAPIRequest(url, 'POST', data)
        this.ctx.body = result.body;
    }
    
}


